#ifndef _BASE_LIBARY_ATOMIC_H_
#define _BASE_LIBARY_ATOMIC_H_
#include "thread_mutex.h"

namespace base_library
{
namespace datastruct
{

template<class _Type>
class atomic
{
public:
	atomic(const _Type &other):m_value(other)
	{

	}
	atomic()
	{

	}
	~atomic()
	{

	}

	friend const atomic<_Type> &operator++(atomic<_Type> &other);
	friend const atomic<_Type> &operator--(atomic<_Type> &other);

	//bool operator==(const _Type &other) const
	//{
	//	thread::recursive_mutex::scoped_lock lock(m_mutex);
	//	return m_value==other;
	//}
	//void operator=(const _Type &other) 
	//{
	//	thread::recursive_mutex::scoped_lock lock(m_mutex);
	//	m_value=other;		
	//}
	operator _Type()
	{
		thread::recursive_mutex::scoped_lock lock(m_mutex);
		return m_value;
	}	
	atomic<_Type> &operator=(const _Type &other)
	{
		thread::recursive_mutex::scoped_lock lock(m_mutex);
		m_value = other;
		return *this;
	}

private:
	atomic<_Type> &operator=(const atomic<_Type> &other);
	atomic(const atomic<_Type> &other);
private:
	thread::recursive_mutex			m_mutex;
	_Type							m_value;
};

}
}










#endif // _BASE_LIBARY_ATOMIC_H_

